<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.54">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0000ff}
span.s3 {color: #0000bf}
span.s4 {color: #000000}
span.s5 {color: #007300}
span.s6 {color: #606060}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>FrameCompare<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>calculates spectral MSE distance of two fft chains</b></p>
<p class="p2"><br></p>
<p class="p1"><b>FrameCompare.kr(buffer1, buffer2, wAmount)</b></p>
<p class="p2"><br></p>
<p class="p1">Given two <a href="SC://FFT"><span class="s2">FFT</span></a> chains, this UGen calculates the MSE between the magnitudes of these two inputs and provides a continuous analytic similarity rating (lower the value, more similar the inputs). In it's current state, only hanning window should be used (wintype: 1).</p>
<p class="p2"><br></p>
<p class="p1"><b>buffer1</b> - FFT chain1</p>
<p class="p1"><b>buffer2</b> - FFT chain2</p>
<p class="p1"><b>wAmount</b> - Influence of the weight matrix (should be between 0 and 1). Weight matrix helps to minimize errors on regions with more energy. Default: 0.5</p>
<p class="p3"><br></p>
<p class="p4">s.boot;</p>
<p class="p3"><br></p>
<p class="p4">(</p>
<p class="p5"><span class="s3">SynthDef</span><span class="s4">(</span>\f_compare<span class="s4">,<span class="Apple-converted-space"> </span></span></p>
<p class="p4">{</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">arg</span> nFreq1 = 220, nQ1 = 0.01, mul = 1, nFreq2 = 2000, nQ2 = 0.01, t_finTrig;</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> in1 = <span class="s3">BPF</span>.ar(<span class="s3">WhiteNoise</span>.ar(mul), nFreq1, nQ1);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> in2 = <span class="s3">BPF</span>.ar(<span class="s3">WhiteNoise</span>.ar(mul), nFreq2, nQ2);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> chain1 = <span class="s3">FFT</span>(<span class="s3">LocalBuf</span>(2048), in1, wintype: 1);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> chain2 = <span class="s3">FFT</span>(<span class="s3">LocalBuf</span>(2048), in2, wintype: 1);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">var</span> fc = <span class="s3">FrameCompare</span>.kr(chain1, chain2, 0.5);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">SendReply</span>.kr(t_finTrig, <span class="s5">'fc_result'</span>, [fc]);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">FreeSelf</span>.kr(t_finTrig);</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s3">Out</span>.ar(0, [in1, in2]);</p>
<p class="p4">}).memStore;</p>
<p class="p3"><br></p>
<p class="p4">r =<span class="Apple-converted-space"> </span></p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span>OSCresponderNode<span class="s4">(</span>nil<span class="s4">, </span><span class="s5">'fc_result'</span><span class="s4">,</span></p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span>{</span>|t, r, msg, other|</p>
<p class="p3"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s6">"FrameCompare result: %"</span>.format(msg[3]).postln;</p>
<p class="p4"><span class="Apple-tab-span">	</span>});</p>
<p class="p4">)</p>
<p class="p3"><br></p>
<p class="p4">r.add;</p>
<p class="p5"><span class="s4">a = </span><span class="s3">Synth</span><span class="s4">(</span>\f_compare<span class="s4">);</span></p>
<p class="p7">//wait for a few seconds</p>
<p class="p4">a.set(<span class="s5">\t_finTrig</span>, 1);</p>
<p class="p3"><br></p>
<p class="p4">a = <span class="s3">Synth</span>(<span class="s5">\f_compare</span>, [<span class="s5">\nFreq2</span>, 4000, <span class="s5">\nQ2</span>, 0.01]);</p>
<p class="p7">//wait for a few seconds</p>
<p class="p4">a.set(<span class="s5">\t_finTrig</span>, 1);</p>
<p class="p3"><br></p>
<p class="p4">a = <span class="s3">Synth</span>(<span class="s5">\f_compare</span>, [<span class="s5">\nFreq2</span>, 220, <span class="s5">\nQ2</span>, 0.5]);</p>
<p class="p7">//wait for a few seconds</p>
<p class="p4">a.set(<span class="s5">\t_finTrig</span>, 1);</p>
<p class="p3"><br></p>
<p class="p7">//same args for noise filters</p>
<p class="p4">a = <span class="s3">Synth</span>(<span class="s5">\f_compare</span>, [<span class="s5">\nFreq2</span>, 220, <span class="s5">\nQ2</span>, 0.01]);</p>
<p class="p7">//wait for a few seconds</p>
<p class="p7"><span class="s4">a.set(</span><span class="s5">\t_finTrig</span><span class="s4">, 1); </span>//most similar</p>
<p class="p8"><br></p>
<p class="p9">r.remove;</p>
<p class="p9">a = nil;</p>
</body>
</html>
